package com.ejlchina.tool.bean

import android.os.Parcelable
import com.huyuhui.fastble.data.BleDevice
import com.ejlchina.tool.enums.AntiPinchModeEnum
import com.ejlchina.tool.enums.FanControlEnum
import com.ejlchina.tool.enums.OnOffEnum
import com.ejlchina.tool.enums.RotateDirectionEnum
import kotlinx.parcelize.Parcelize


data class FunctionBean(val index: Int,val imgResId: Int, val textResId: Int, val action: () -> Unit)

//upgradeResult参数 -1表示失败，0-99表示正常进度，100表示成功
@Parcelize
data class BleDeviceBean(
    val bleDevice: BleDevice,
    var version: String = "", //固件版本
    var hardVersion: String = "", //硬件版本
    var upgradeToVersion: String = "",
    var isConnect: Boolean = true,
    var isSelect: Boolean = false,
    var upgradeResult: Float = 0F,
    var bucketNo: Int = -1,//通许标定字段，-1表示未设置
    var deviceNo: String = "", //绑定的设备编号
    var isOpenLight: Boolean = false,
    var rssi: Int = -100,
    var indexInOffline: Int = 0, //单机版固件升级时候用
    var isWaterCoverOn: Boolean = false,  //水浸是不是打开-首页用
    var isMachineAntiPinchOn: Boolean = false,  //机械防夹是不是打开-首页用
    var scanOrCard: Int = 0, //扫描头还是刷卡板 0-扫描头，1-刷卡板
    var isEncrypt: Boolean = false //是否加密
) : Parcelable {
    fun isInFirmwareUpgrade(): Boolean {
        return upgradeResult > 0f && upgradeResult < 100f
    }

    fun isReadToUpgrade(): Boolean {
        return upgradeResult == 0F
    }

    fun isInOrFinishUpgrade(): Boolean {
        return upgradeResult == -1F || upgradeResult > 0F
    }
    fun getRealUpgradeVersion(): String{
        return if (isInFirmwareUpgrade()){
            upgradeToVersion
        }else {
            ""
        }
    }

    fun getBucketNoString(): String{
        return if (bucketNo == -1) "" else "$bucketNo#"
    }

    fun getDeviceNoString(): String{
        return deviceNo.ifEmpty { "暂无" }
    }
}

data class FirmwareUpgradeDialogBean(val bleDevice: BleDevice, val progressOrResult: String)

data class IndicatorDataBean(val bleDevice: BleDevice, var resultData: ByteArray)
data class IndicatorDeviceDataBean(val bleDevice: BleDeviceBean, var resultData: ByteArray)
data class IndicatorResultBean(val bleDevice: BleDeviceBean, val isSuccess: Boolean)

data class BottomSheetCommonBean(val valueList: List<BottomSheetItemBean>)


data class BottomSheetItemBean(val index: Int, val valueString: String, var isSelect: Boolean)

data class PushRodBean(
    var machineAntiPinch: AntiPinchModeEnum = AntiPinchModeEnum.NO_ANTI_PINCH,
    var electricAntiPinch: OnOffEnum = OnOffEnum.OFF,
    var rotateDirection: RotateDirectionEnum = RotateDirectionEnum.CW,
    var autoCloseDelay: Int = 5,
    var closeSectionCount: Int = 1,
    var closeSectionDuration: Int = 10,
    var closeSectionDelay: Int = 5
)

data class NpnInputBean(
    var smoke: Boolean = false,
    var full: Boolean = false,
    var body: Boolean = false,
    var button: Boolean = false,
    var lock: Boolean = false,
    var machineAntiPinch: Boolean = false,
    var reuse: Boolean = false,
    var reserveInput: Boolean = false
)

data class ExtendSerialPortBean(
    var distanceSensor: Boolean = false,
    var waterSensor: Boolean = false,
    var weightSensor: Boolean = false,
    var bottleCountSensor: Boolean = false
)

data class TemperatureAlarmBean(
    var highTemperature: Int = 80,
    var lowTemperature: Int = -20,
    var fanControl: FanControlEnum = FanControlEnum.OFF,
    var fanControlTemperature: Int = 50
)
data class DoorControlBean(
    var buttonOpenDoor: Boolean = false,
    var bodyOpenDoor: Boolean = false,
    var bodyAntiPinch: Boolean = false,
    var authorizationTime: Int = 10
)

data class FullAndDistanceBean(
    var fullFar: Int = 160, //单位厘米
    var fullNear: Int = 20
)

data class LightTimeBean(
    var startTime: TimeBean = TimeBean(),
    var endTime: TimeBean = TimeBean()
)

data class TimeBean(
    var hour: Int = 0,
    var minute: Int = 0
)

data class DeviceVersionsBean(
    val mac: String,
    var firmwareVersion: String,
    var hardVersion: String
)

data class ConfigWarningBean(
    val index: Int,
    val key: String,
    var value: String = "-",
    var isNormal: Boolean = true
)

data class ReuseFunctionBean(
    var autoBrokenOn: Boolean = false,
    var bottleDeliverOn: Boolean = false,
    var bottleCountOn: Boolean = false,
    var deodorization: Boolean = false,
    var lightShield: Boolean = false
){
    fun closeReuseFunction(){
        autoBrokenOn = false
        bottleDeliverOn = false
        bottleCountOn = false
        deodorization = false
        lightShield = false
    }
}

data class Command(val pageIndex: Int,val commandString: String = "",var commandData: String = "")

data class VersionResBean(
    val code: Int,
    val description: String,
    val url: String,
    val versionNo: String
)